package org.jackysoft.jms;

import javax.annotation.Resource;
import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.Session;

import org.apache.activemq.command.ActiveMQQueue;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.jms.core.JmsTemplate;
import org.springframework.jms.core.MessageCreator;
import org.springframework.stereotype.Component;

@Component
public class MessageSender {
	
	static final Log logger = LogFactory.getLog(MessageSender.class);
	private JmsTemplate jmsTemplate;

	private ActiveMQQueue destination;
	@Resource
	public void setJmsTemplate(JmsTemplate jmsTemplate) {
		this.jmsTemplate = jmsTemplate;
	}

	@Resource(name="queueDestination")
	public void setDestination(ActiveMQQueue quee){
		this.destination = quee;
	}
	public void send(final String text ) {
		
		
		jmsTemplate.send(destination,new MessageCreator() {
           
			public Message createMessage(Session session) throws JMSException {
				logger.info("发送消息:"+text);		
				return session.createTextMessage(text);
			}
		});
	}	
	
}
